//
//  MainViewController.swift
//  SinaWebo
//
//  Created by mis on 16/3/17.
//  Copyright © 2016年 mis. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    @objc private func composeDidClick() {
        let compose = ComposeViewController()
        let nav = UINavigationController(rootViewController: compose)
        self.presentViewController(nav, animated: true, completion: nil)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        let mainTabBar = MainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
        addChildViewControllers()
        mainTabBar.compaseBtn.addTarget(self, action: "composeDidClick", forControlEvents: .TouchUpInside)
    }
    
    private func addChildViewControllers() {
        
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "信息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    private func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        let nav = BaseNavViewController(rootViewController: vc)
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
//        tabBar.tintColor = UIColor.orangeColor()
        addChildViewController(nav)
    }

}
